package game.buildings;

/**
 *	@(#)Building.java
 *
 *	The <code>Building</code> class represents an abstract building
 *	and is the superclass of all buildings in the game.
 *
 *	@author Grzegorz Kobiela
 *	@version 1.0 2008/5/8
 */
public abstract class Building
extends game.GameObject
{
	/**
	 *	The building type.
	 */
	protected BuildingType type;

	/** The location. */
	protected java.awt.Point location;

	/**
	 *	Creates a new <code>Building</code> with the given building type.
	 *	@param type the building type
	 */
	protected Building(BuildingType type) {
		this.type = type;
		location = null;
	}

	/**
	 *	Returns the type of the building.
	 *	@return building type
	 */
	public BuildingType getType() {
		return type;
	}

	/**
	 *	Returns the location.
	 *	@return the location
	 */
	public java.awt.Point getLocation() {
		return (location != null ? new java.awt.Point(location) : null);
	}

	/**
	 *	Sets the location to the given point.
	 *	@param location the new location
	 */
	public void setLocation(java.awt.Point location) {
		this.location = (location != null ? new java.awt.Point(location) : null);
	}

	/**
	 *	Factory method to create buildings by their type.
	 *	@param type the building type
	 *	@param args specifying arguments
	 */
	public static Building createBuilding(BuildingType type, Object... args) {
		switch(type) {
			case ALCHEMY: return new Alchemy();
			case BIOLOGY: return new Biology();
			case BREWERY: return new Brewery();
			case CARTSHOP: return new Cartshop();
			case CATHEDRAL: return new Cathedral();
			case CITY: return ((args != null && args.length > 0) ? new City((game.PlayerColor)args[0]) : null);	// expects the color
			case DUMP: return new Dump();
			case EXPLORER: return new Explorer();
			case FARM: return new Farm();
			case FISHERMAN: return new Fisherman();
			case FORCEDLABOUR: return new ForcedLabour();
			case FOUNTAIN: return new Fountain();
			case GRANARY: return new Granary();
			case GRAVE: return new Grave();
			case HARBOUR: return new Harbour();
			case HOSPITAL: return new Hospital();
			case HOUSE: return ((args != null && args.length > 0) ? new House((Integer)args[0]) : null);		// expects the index
			case INN: return ((args != null && args.length > 0) ? new Inn((game.PlayerColor)args[0]) : null);	// expects the color
			case MARKET: return new Market();
			case MINE: return new Mine();
			case PHILOSOPHY: return new Philosophy();
			case STABLES: return new Stables();
			case STORAGE: return new Storage();
			case THEOLOGY: return new Theology();
			case UNIVERSITY: return new University();
			case WOODCUTTER: return new Woodcutter();
			default: return null;
		}
	}
}